package com.tan.chowder.bean;


import com.tan.chowder.login.constan.ResultCode;
import lombok.Data;

/**
 * @author chenx
 * @version 1.0
 * @description: TODO
 * @date 2024/5/9 0:14
 */

@Data
public class Result {
    private int code;

    private String message = "success";

    private Object data;

    public static Result success() {
        Result result = new Result();
        result.code = ResultCode.SUCCESS.code;
        result.message = ResultCode.SUCCESS.getMessage();
        result.data = null;
        return result;
    }

    // 后面result生成器需要以下方法
    public Result setCode(ResultCode resultCode){
        this.code = resultCode.code;
        return this;
    }

    public Result setMessage(String message){
        this.message = message;
        return this;
    }

    public Result setData(Object data){
        this.data = data;
        return this;
    }
    public Result ok(Object data){
        this.code = ResultCode.SUCCESS.code;
        this.message = ResultCode.SUCCESS.getMessage();
        this.data = data;
        return this;
    }
    public Result error(String errorMessage){
        Result result = new Result();
        result.code = ResultCode.FAIL.code;
        result.message = errorMessage;
        result.data = null;
        return result;
    }

    public Result(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result() {
    }
}
